package StudyCode.summary.Basic.mystring;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class StringPalindrome {
	public static void main(String[] args) {
		String str1 = "Today";
		boolean b1 = isPalindrome(str1);
		System.out.println(str1 + " 是不是回文串: " + b1);

		String str2 = "level";
		boolean b2 = isPalindrome(str2);
		System.out.println(str2 + " 是不是回文串: " + b2);
	}

	public static boolean isPalindrome(String inputString) {

		if (inputString == null) {
			throw new IllegalArgumentException("String cannot be null.");
		}

		int len = inputString.length();
		if (len <= 1) {
			return true;
		}

		String newStr = inputString.toUpperCase();
		boolean result = true;
		int counter = len / 2;
		for (int i = 0; i < counter; i++) {
			if (newStr.charAt(i) != newStr.charAt(len - 1 - i)) {
				result = false;
				break;
			}
		}
		return result;
	}
}
